<?php
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MVC.
 *
 * PHP-MVC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MVC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MVC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-mvc/view
 * @subpackage  form
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */

/**
 * Zend class for extension
 */
require_once 'mvc/view/helper/zend/FormElement.php';


/**
 * Helper to generate a "input type="submit"" element thats acts as a Cancel-button.
 *
 * The request will be sent the same way as with a normal submit button. But if this button is used, Action::isCancelled($request)
 * returns true;
 *
 * @category   Melange
 * @package    php-mvc
 * @subpackage view
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (jeroen@melange.nl)
 * @license    http://www.gnu.org/licenses/licenses.html#GPL    The GNU General Public License
 */
class PHP_MVC_View_Form_Helper_FormCancel extends Zend_View_Helper_FormElement {

    /**
     * Generates a 'Cancel' button.
     *
     * @access public
     *
     * @param string $name Should always be CANCEL_KEY.
     *
     * @param mixed $value The element value.
     *
     * @param array $attribs Attributes for the element tag.
     *
     * @return string The element XHTML.
     */
    public function formCancel($name=CANCEL_KEY, $value = 'Cancel', $attribs = null)
    {
        $info = $this->_getInfo($name, $value, $attribs);
        extract($info); // name, value, attribs, options, listsep, disable

        // always enabled
        $xhtml = '<input type="submit"'
               . ' name="' . htmlspecialchars(CANCEL_KEY, ENT_COMPAT, 'UTF-8') . '"'
               . ' id="' . htmlspecialchars($id, ENT_COMPAT, 'UTF-8') . '"';

        // add a value if one is given
        if (! empty($value)) {
            $xhtml .= ' value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"';
        }

        // add attributes, close, and return
        $xhtml .= $this->_htmlAttribs($attribs) . ' />';
        return $xhtml;
    }
}
?>